//
//  NSDictionary+JKBase.m
//  JKFoundation
//
//  Created by JK on 07/08/2017.
//  Copyright © 2017 Shanghai DataSeed Information Technology Co.,Ltd. All rights reserved.
//

#import "NSDictionary+JKBase.h"

extern NSDictionary* JKTextAattributes(UIColor *color, UIFont *font) {
    return [NSDictionary attributesWithColor:color font:font];
}

@implementation NSDictionary (JKBase)


+ (NSDictionary *)attributesWithColor:(UIColor *)color font:(UIFont *)font
{
    NSMutableDictionary *attributes = [[NSMutableDictionary alloc]init];
    
    if (color != nil) {
        [attributes setObject:color forKey:NSForegroundColorAttributeName];
    }
    
    if (font != nil) {
        [attributes setObject:font forKey:NSFontAttributeName];
    }
    
    return attributes;
}

+ (NSDictionary *)attributesWithColor:(UIColor *)color font:(UIFont *)font alignment:(NSTextAlignment)alignment lineSpacing:(NSNumber*)lineSpacing{
    NSMutableDictionary *attributes = [[NSMutableDictionary alloc]init];
    
    if (color != nil) {
        [attributes setObject:color forKey:NSForegroundColorAttributeName];
    }
    
    if (font != nil) {
        [attributes setObject:font forKey:NSFontAttributeName];
    }
    
    NSMutableParagraphStyle* paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
    paragraphStyle.alignment = alignment;
    
    if (lineSpacing != nil) {
        paragraphStyle.lineSpacing = lineSpacing.floatValue;
    }
    
    [attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
    
    return attributes;
}
+ (NSDictionary *)attributesWithColor:(UIColor *)color font:(UIFont *)font paragraphStyle:(NSMutableParagraphStyle *)paragraphStyle{
    NSMutableDictionary *attributes = [[NSMutableDictionary alloc]init];
    
    if (color != nil) {
        [attributes setObject:color forKey:NSForegroundColorAttributeName];
    }
    
    if (font != nil) {
        [attributes setObject:font forKey:NSFontAttributeName];
    }
    
    if (paragraphStyle != nil) {
        [attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
    }
    
    return attributes;
}


@end
